<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <title>Sign in &laquo; Admin</title>
    <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../assets/css/admin.css">
</head>

<body>
    <div class="login">
        <div class="login-wrap">
            <img class="avatar" src="../assets/img/default.png">
            <!-- 有错误信息时展示 -->
            <!-- <div class="alert alert-danger">
        <strong>错误！</strong> 用户名或密码错误！
      </div> -->
            <div class="form-group">
                <label for="email" class="sr-only">邮箱</label>
                <input id="email" type="email" class="form-control" placeholder="邮箱" autofocus>
            </div>
            <div class="form-group">
                <label for="password" class="sr-only">密码</label>
                <input id="password" type="password" class="form-control" placeholder="密码">
            </div>
            <button class="btn btn-primary btn-block login-btn">登 录</button>
        </div>
    </div>
    @@include('../comm/base.html')
    <script>
        //绑定点击事件
        $('.login-btn').click(function() {
            console.log('-------------');

            const email = $('#email').val()
            const pwd = $('#password').val()
            console.log('email', email);
            console.log('pwd', pwd);
            console.log('email', email.trim());
            if (!email.trim()) {
                alert('请输入邮箱')
                return
            }

            if (!pwd.trim()) {
                alert('请输入密码')
                return
            }
            const params = {
                email,
                password: pwd
            }
            $.ajax(`${baseUrl}/login`, {
                type: 'post',
                data: params,
                success: function(res) {
                    console.log('登录成功：', res);
                    const token = res.token
                    if (token) {
                        localStorage.setItem('token', token)
                        location.href = '/admin/index.html'
                    } else {
                        alert('登录失败！')
                    }
                },
                error: function(err) {
                    console.log('登录失败：', err);
                    alert('登录失败：', err)
                }
            })

        })
    </script>
</body>

</html>